package base_demo.test1;

public class MyThread extends Thread{
    public MyThread() {
    }

    public MyThread(String name) {
        super(name);
    }

    static int ticket = 0;
    //static Object obj = new Object();
    @Override
    public void run() {
        while(true){
           synchronized(MyThread.class){
               if(ticket < 100){
                   try {
                       Thread.sleep(100);
                   } catch (InterruptedException e) {
                       throw new RuntimeException(e);
                   }
                   ticket++;
                   System.out.println(getName() + "正在售卖第" + ticket + "张票");
               } else {
                   break;
               }

           }
        }
    }
}
